package orest.back.stat;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import orest.back.userneeds.UserNeedsHandler;
import orest.front.achieve.AchieveHandler;




import net.ssta.common.Constants;
import net.ssta.core.base.ServletBase;
import net.ssta.core.db.PagingInfo;
import net.ssta.core.db.RecordSet;
import net.ssta.core.db.Record;
import net.ssta.core.util.DateUtility;
import net.ssta.core.util.UUIDGenerator;
import net.ssta.core.web.RequestKit;
import net.ssta.util.fusionchart.FusionCharts;

public class StatServlet extends ServletBase {

	protected void defaultAction(HttpServletRequest request, HttpServletResponse response) throws IOException
	{
			System.out.println("UserNeedsServlet default Action");
	}
	
	
	
	/**
     * 科技成果数量统计
     * 
     * @param request
     * @param response
     */
    public void kjcgSlStat(HttpServletRequest request,
        HttpServletResponse response)
    {
    	try {
			try {
				
				RequestKit requestKit = (RequestKit) request.getAttribute("RequestKit");
		        
				Record searchRcd = requestKit.getRecordWithPrefix("sea_");
				
				String startyear = requestKit.getParameter("sea_startyear", "");
	            String endyear = requestKit.getParameter("sea_endyear", "");
	            
	            if(startyear.equals("")&&endyear.equals("")){
	            	endyear = DateUtility.getCurrentDate().substring(0,4);
	            	startyear = new Integer(new Integer(endyear).intValue()-6).toString();
	            	searchRcd.addData("STARTYEAR", startyear);
	            	searchRcd.addData("ENDYEAR", endyear);
	            }
				
		        
		        
		        StatHandler infoRecom = new StatHandler();
		        RecordSet recordSet = infoRecom.kjcgSlStat(startyear,endyear);
		        
		        
		        FusionCharts cb=new FusionCharts("历年科技成果趋势图");
	    		
	    		cb.setXAxisName("年份");
	    		cb.setYAxisName("成果数量");
	    		cb.setChartAttribute("LABELDISPLAY", "Rotate");
	    		cb.setChartAttribute("SLANTLABELS", "1");
	    		
	    		Double sum = 0d;
	    		for(int i=0;i<recordSet.size();i++){
	    			Record record = recordSet.get(i);
	    			cb.addDataByNoLink(record.getString("KJCG_YEAR",""),"",new Double(record.getString("TOTAL")).doubleValue());
	    			sum += new Double(record.getString("TOTAL")).doubleValue();
	    		}
	    		
	    		FusionCharts cb2=new FusionCharts("成果数量统计图");
	    		
	    		for(int i=0;i<recordSet.size();i++){
	    			Record record = recordSet.get(i);
	    			cb2.addDataByNoLink(record.getString("KJCG_YEAR",""),new Double(record.getString("TOTAL")).doubleValue());
	    			
	    			Double total_d = new Double(record.getString("TOTAL")).doubleValue();
	    			double per_d = total_d/sum*100;
	    			DecimalFormat df = new DecimalFormat("##.##");  
	    			(recordSet.get(i)).addData("PER", df.format(per_d));
	    		}
	    		
		        
	    		String filepath = "/stat/xml/"+UUIDGenerator.getUUID()+".xml";
	    		String realpath = request.getRealPath(filepath);
	    		String url1 = filepath;
	    		File xmlFile = new File(realpath);
	    		cb.saveDataAsXml("MSLine", xmlFile); 
	    		
	    		filepath = "/stat/xml/"+UUIDGenerator.getUUID()+".xml";
	    		realpath = request.getRealPath(filepath);
	    		String url2 = filepath;
	    		xmlFile = new File(realpath);
	    		cb2.saveDataAsXml("Column3D", xmlFile);
	    		
	    		request.setAttribute("sum", sum);
	    		request.setAttribute("recordSet", recordSet);
		        request.setAttribute("searchRcd", searchRcd);
		        request.setAttribute("url1", url1);
		        request.setAttribute("url2", url2);
		        
				
				forward("/stat/NianduQuShiZXT.jsp");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} catch (ServletException e) {
			e.printStackTrace();
		}
    }
    
    
    
    
    
    /**
     * 按课题来源统计
     * 
     * @param request
     * @param response
     */
    public void keTiLaiYuan(HttpServletRequest request,HttpServletResponse response)
    {
    	try { 
			try {
				
				RequestKit requestKit = (RequestKit) request.getAttribute("RequestKit");
		        
				Record searchRcd = requestKit.getRecordWithPrefix("sea_");
				
				String startyear = requestKit.getParameter("sea_startyear", "");
	            String endyear = requestKit.getParameter("sea_endyear", "");
	            
	            if(startyear.equals("")&&endyear.equals("")){
	            	endyear = DateUtility.getCurrentDate().substring(0,4);
	            	startyear = new Integer(new Integer(endyear).intValue()-6).toString();
	            	searchRcd.addData("STARTYEAR", startyear);
	            	searchRcd.addData("ENDYEAR", endyear);
	            }
		        
		        
		        StatHandler infoRecom = new StatHandler();
		        RecordSet recordSet = infoRecom.keTiLaiYuan(startyear,endyear);
		        
		        
		        FusionCharts cb=new FusionCharts("按课题来源统计");
	    		
	    		cb.setXAxisName("年份");
	    		cb.setYAxisName("成果数量");
	    		cb.setChartAttribute("LABELDISPLAY", "Rotate");
	    		cb.setChartAttribute("SLANTLABELS", "1");
	    		
	    		//各种分类的数量
	    		Map countMap = new HashMap();
	    		
	    		Map tmap = new HashMap();
	    		double sum = 0;
	    		for(int i=0;i<recordSet.size();i++){
	    			Record record = recordSet.get(i);
	    			cb.addDataByNoLink(record.getString("KJCG_YEAR",""),record.getString("XXMC",""),new Integer(record.getString("TOTAL","0")).intValue());
	    			
	    			sum += new Double(record.getString("TOTAL","0")).doubleValue();
	    			
	    			tmap.put(record.getString("KJCG_YEAR","")+record.getString("XXMC",""), record.getString("TOTAL","0"));
	    			
	    			if(countMap.get(record.getString("XXMC",""))==null){
	    				countMap.put(record.getString("XXMC",""), new Integer(record.getString("TOTAL","0")));
	    			}else{
	    				countMap.put(record.getString("XXMC",""),((Integer)countMap.get(record.getString("XXMC",""))).intValue() + new Integer(record.getString("TOTAL","0")).intValue());
	    			}
	    		}
	    		
	    		UserNeedsHandler uhandler = new UserNeedsHandler();
	    		RecordSet ktdmSet =  uhandler.getZdxx("ITEM_126");
	    		 
	    		//不存在的分类填充0
	    		for(int i=new Integer(startyear).intValue();i<=new Integer(endyear).intValue();i++){
	    			for(int j=0;j<ktdmSet.size();j++){
	    				if(tmap.get(new Integer(i).toString()+ktdmSet.get(j).getString("XXMC", ""))==null){
	    					cb.addDataByNoLink(new Integer(i).toString(),ktdmSet.get(j).getString("XXMC", ""),0);
	    				}
	    			}
	    		}
	    		
	    		//记录各分类数量
	    		for(int i=0;i<ktdmSet.size();i++){
	    			String total = "";
	    			if(countMap.get(ktdmSet.get(i).getString("XXMC",""))!=null){
	    				total = ((Integer)(countMap.get(ktdmSet.get(i).getString("XXMC","")))).toString();
	    				double total_d = new Double(total).doubleValue(); 
		    			double per_d = total_d/sum*100;
		    		    (ktdmSet.get(i)).addData("TOTAL", total);
		    			 DecimalFormat df = new DecimalFormat("##.##");  
		    			 (ktdmSet.get(i)).addData("PER", df.format(per_d));
	    			}else{
	    				(ktdmSet.get(i)).addData("TOTAL", "0");
		    			(ktdmSet.get(i)).addData("PER", "0.0");
	    			}
	    		}
	    		
	    		
	    		
	    		
	    		
	    		
	    		
	    		FusionCharts cb2=new FusionCharts("按课题来源统计饼状图");
	    		
	    		for(int i=0;i<ktdmSet.size();i++){
	    			Record record = ktdmSet.get(i);
	    			cb2.addDataByNoLink(record.getString("XXMC",""),new Double(record.getString("TOTAL")).doubleValue());
	    		}
	    		
		        
	    		String filepath = "/stat/xml/"+UUIDGenerator.getUUID()+".xml";
	    		String realpath = request.getRealPath(filepath);
	    		String url1 = filepath;
	    		File xmlFile = new File(realpath);
	    		cb.saveDataAsXml("MSColumn3D", xmlFile);
	    		
	    		filepath = "/stat/xml/"+UUIDGenerator.getUUID()+".xml";
	    		realpath = request.getRealPath(filepath);
	    		String url2 = filepath;
	    		xmlFile = new File(realpath);
	    		cb2.saveDataAsXml("Pie3D", xmlFile);
	    		
	    		request.setAttribute("sum", sum);
	    		request.setAttribute("recordSet", recordSet);
		        request.setAttribute("searchRcd", searchRcd);
		        request.setAttribute("ktdmSet", ktdmSet);
		        request.setAttribute("url1", url1);
		        request.setAttribute("url2", url2);
		        request.setAttribute("countMap", countMap);
		        
		       // request.setAttribute("url2", url2);
				
				forward("/stat/KeTiLaiYuan.jsp");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} catch (ServletException e) {
			e.printStackTrace();
		}
    }
    
    
    
    /**
     * 按成果水平统计
     * 
     * @param request
     * @param response
     */
    public void ShueiPing(HttpServletRequest request,HttpServletResponse response)
    {
    	try { 
			try {
				
				RequestKit requestKit = (RequestKit) request.getAttribute("RequestKit");
		        
				Record searchRcd = requestKit.getRecordWithPrefix("sea_");
				
				String startyear = requestKit.getParameter("sea_startyear", "");
	            String endyear = requestKit.getParameter("sea_endyear", "");
	            
	            if(startyear.equals("")&&endyear.equals("")){
	            	endyear = DateUtility.getCurrentDate().substring(0,4);
	            	startyear = new Integer(new Integer(endyear).intValue()-6).toString();
	            	searchRcd.addData("STARTYEAR", startyear);
	            	searchRcd.addData("ENDYEAR", endyear);
	            }
		        
		        
		        StatHandler infoRecom = new StatHandler();
		        RecordSet recordSet = infoRecom.ShueiPing(startyear,endyear);
		        
		        
		        FusionCharts cb=new FusionCharts("科技成果成果水平分布统计");
	    		
	    		cb.setXAxisName("年份");
	    		cb.setYAxisName("成果数量");
	    		cb.setChartAttribute("LABELDISPLAY", "Rotate");
	    		cb.setChartAttribute("SLANTLABELS", "1");
	    		
	    		//各种分类的数量
	    		Map countMap = new HashMap();
	    		
	    		Map tmap = new HashMap();
	    		double sum = 0;
	    		for(int i=0;i<recordSet.size();i++){
	    			Record record = recordSet.get(i);
	    			cb.addDataByNoLink(record.getString("KJCG_YEAR",""),record.getString("XXMC",""),new Integer(record.getString("TOTAL","0")).intValue());
	    			
	    			sum += new Double(record.getString("TOTAL","0")).doubleValue();
	    			
	    			tmap.put(record.getString("KJCG_YEAR","")+record.getString("XXMC",""), record.getString("TOTAL","0"));
	    			
	    			if(countMap.get(record.getString("XXMC",""))==null){
	    				countMap.put(record.getString("XXMC",""), new Integer(record.getString("TOTAL","0")));
	    			}else{
	    				countMap.put(record.getString("XXMC",""),((Integer)countMap.get(record.getString("XXMC",""))).intValue() + new Integer(record.getString("TOTAL","0")).intValue());
	    			}
	    		}
	    		
	    		UserNeedsHandler uhandler = new UserNeedsHandler();
	    		RecordSet ktdmSet =  uhandler.getZdxx("ITEM_2");
	    		
	    		//不存在的分类填充0
	    		for(int i=new Integer(startyear).intValue();i<=new Integer(endyear).intValue();i++){
	    			for(int j=0;j<ktdmSet.size();j++){
	    				if(tmap.get(new Integer(i).toString()+ktdmSet.get(j).getString("XXMC", ""))==null){
	    					cb.addDataByNoLink(new Integer(i).toString(),ktdmSet.get(j).getString("XXMC", ""),0);
	    				}
	    			}
	    		}
	    		
	    		//记录各分类数量
	    		for(int i=0;i<ktdmSet.size();i++){
	    			String total = "";
	    			if(countMap.get(ktdmSet.get(i).getString("XXMC",""))!=null){
	    				total = ((Integer)(countMap.get(ktdmSet.get(i).getString("XXMC","")))).toString();
	    				double total_d = new Double(total).doubleValue(); 
		    			double per_d = total_d/sum*100;
		    		    (ktdmSet.get(i)).addData("TOTAL", total);
		    			 DecimalFormat df = new DecimalFormat("##.##");  
		    			 (ktdmSet.get(i)).addData("PER", df.format(per_d));
	    			}else{
	    				(ktdmSet.get(i)).addData("TOTAL", "0");
		    			(ktdmSet.get(i)).addData("PER", "0.0");
	    			}
	    		}
	    		
	    		
	    		
	    		
	    		
	    		
	    		
	    		FusionCharts cb2=new FusionCharts("科技成果成果水平分布统计");
	    		
	    		for(int i=0;i<ktdmSet.size();i++){
	    			Record record = ktdmSet.get(i);
	    			cb2.addDataByNoLink(record.getString("XXMC",""),new Double(record.getString("TOTAL")).doubleValue());
	    		}
	    		
		        
	    		String filepath = "/stat/xml/"+UUIDGenerator.getUUID()+".xml";
	    		String realpath = request.getRealPath(filepath);
	    		String url1 = filepath;
	    		File xmlFile = new File(realpath);
	    		cb.saveDataAsXml("MSColumn3D", xmlFile);
	    		
	    		filepath = "/stat/xml/"+UUIDGenerator.getUUID()+".xml";
	    		realpath = request.getRealPath(filepath);
	    		String url2 = filepath;
	    		xmlFile = new File(realpath);
	    		cb2.saveDataAsXml("Pie3D", xmlFile);
	    		
	    		
	    		request.setAttribute("sum", sum);
	    		request.setAttribute("recordSet", recordSet);
		        request.setAttribute("searchRcd", searchRcd);
		        request.setAttribute("ktdmSet", ktdmSet);
		        request.setAttribute("url1", url1);
		        request.setAttribute("url2", url2);
		        request.setAttribute("countMap", countMap);
		        
		       // request.setAttribute("url2", url2);
				
				forward("/stat/ShueiPing.jsp");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} catch (ServletException e) {
			e.printStackTrace();
		}
    }
    
    
    
    
    
    /**
     * 按研究形式统计
     * 
     * @param request
     * @param response
     */
    public void yanjiuXingShi(HttpServletRequest request,HttpServletResponse response)
    {
    	try { 
			try {
				
				RequestKit requestKit = (RequestKit) request.getAttribute("RequestKit");
		        
				Record searchRcd = requestKit.getRecordWithPrefix("sea_");
				
				String startyear = requestKit.getParameter("sea_startyear", "");
	            String endyear = requestKit.getParameter("sea_endyear", "");
	            
	            if(startyear.equals("")&&endyear.equals("")){
	            	endyear = DateUtility.getCurrentDate().substring(0,4);
	            	startyear = new Integer(new Integer(endyear).intValue()-6).toString();
	            	searchRcd.addData("STARTYEAR", startyear);
	            	searchRcd.addData("ENDYEAR", endyear);
	            }
		        
		        
		        StatHandler infoRecom = new StatHandler();
		        RecordSet recordSet = infoRecom.yanjiuXingShi(startyear,endyear);
		        
		        
		        FusionCharts cb=new FusionCharts("科技成果研究形式布统计");
	    		
	    		cb.setXAxisName("年份");
	    		cb.setYAxisName("成果数量");
	    		cb.setChartAttribute("LABELDISPLAY", "Rotate");
	    		cb.setChartAttribute("SLANTLABELS", "1");
	    		
	    		//各种分类的数量
	    		Map countMap = new HashMap();
	    		
	    		Map tmap = new HashMap();
	    		double sum = 0;
	    		for(int i=0;i<recordSet.size();i++){
	    			Record record = recordSet.get(i);
	    			cb.addDataByNoLink(record.getString("KJCG_YEAR",""),record.getString("XXMC",""),new Integer(record.getString("TOTAL","0")).intValue());
	    			
	    			sum += new Double(record.getString("TOTAL","0")).doubleValue();
	    			
	    			tmap.put(record.getString("KJCG_YEAR","")+record.getString("XXMC",""), record.getString("TOTAL","0"));
	    			
	    			if(countMap.get(record.getString("XXMC",""))==null){
	    				countMap.put(record.getString("XXMC",""), new Integer(record.getString("TOTAL","0")));
	    			}else{
	    				countMap.put(record.getString("XXMC",""),((Integer)countMap.get(record.getString("XXMC",""))).intValue() + new Integer(record.getString("TOTAL","0")).intValue());
	    			}
	    		}
	    		
	    		UserNeedsHandler uhandler = new UserNeedsHandler();
	    		RecordSet ktdmSet =  uhandler.getZdxx("ITEM_201");
	    		
	    		//不存在的分类填充0
	    		for(int i=new Integer(startyear).intValue();i<=new Integer(endyear).intValue();i++){
	    			for(int j=0;j<ktdmSet.size();j++){
	    				if(tmap.get(new Integer(i).toString()+ktdmSet.get(j).getString("XXMC", ""))==null){
	    					cb.addDataByNoLink(new Integer(i).toString(),ktdmSet.get(j).getString("XXMC", ""),0);
	    				}
	    			}
	    		}
	    		
	    		//记录各分类数量
	    		for(int i=0;i<ktdmSet.size();i++){
	    			String total = "";
	    			if(countMap.get(ktdmSet.get(i).getString("XXMC",""))!=null){
	    				total = ((Integer)(countMap.get(ktdmSet.get(i).getString("XXMC","")))).toString();
	    				double total_d = new Double(total).doubleValue(); 
		    			double per_d = total_d/sum*100;
		    		    (ktdmSet.get(i)).addData("TOTAL", total);
		    			 DecimalFormat df = new DecimalFormat("##.##");  
		    			 (ktdmSet.get(i)).addData("PER", df.format(per_d));
	    			}else{
	    				(ktdmSet.get(i)).addData("TOTAL", "0");
		    			(ktdmSet.get(i)).addData("PER", "0.0");
	    			}
	    		}
	    		
	    		
	    		
	    		
	    		
	    		
	    		
	    		FusionCharts cb2=new FusionCharts("科技成果研究形式布统计");
	    		
	    		for(int i=0;i<ktdmSet.size();i++){
	    			Record record = ktdmSet.get(i);
	    			cb2.addDataByNoLink(record.getString("XXMC",""),new Double(record.getString("TOTAL")).doubleValue());
	    		}
	    		
		        
	    		String filepath = "/stat/xml/"+UUIDGenerator.getUUID()+".xml";
	    		String realpath = request.getRealPath(filepath);
	    		String url1 = filepath;
	    		File xmlFile = new File(realpath);
	    		cb.saveDataAsXml("MSColumn3D", xmlFile);
	    		
	    		filepath = "/stat/xml/"+UUIDGenerator.getUUID()+".xml";
	    		realpath = request.getRealPath(filepath);
	    		String url2 = filepath;
	    		xmlFile = new File(realpath);
	    		cb2.saveDataAsXml("Pie3D", xmlFile);
	    		
	    		request.setAttribute("sum", sum);
	    		request.setAttribute("recordSet", recordSet);
		        request.setAttribute("searchRcd", searchRcd);
		        request.setAttribute("ktdmSet", ktdmSet);
		        request.setAttribute("url1", url1);
		        request.setAttribute("url2", url2);
		        request.setAttribute("countMap", countMap);
		        
		       // request.setAttribute("url2", url2);
				
				forward("/stat/YanjiuXingShi.jsp");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} catch (ServletException e) {
			e.printStackTrace();
		}
    }
    
    
    
    
    
    
    
    
    /**
     * 按体现形式统计
     * 
     * @param request
     * @param response
     */
    public void tiXianXingshiShi(HttpServletRequest request,HttpServletResponse response)
    {
    	try { 
			try {
				
				RequestKit requestKit = (RequestKit) request.getAttribute("RequestKit");
		        
				Record searchRcd = requestKit.getRecordWithPrefix("sea_");
				
				String startyear = requestKit.getParameter("sea_startyear", "");
	            String endyear = requestKit.getParameter("sea_endyear", "");
	            
	            if(startyear.equals("")&&endyear.equals("")){
	            	endyear = DateUtility.getCurrentDate().substring(0,4);
	            	startyear = new Integer(new Integer(endyear).intValue()-6).toString();
	            	searchRcd.addData("STARTYEAR", startyear);
	            	searchRcd.addData("ENDYEAR", endyear);
	            }
		        
		        
		        StatHandler infoRecom = new StatHandler();
		        RecordSet recordSet = infoRecom.tiXianXingshiShi(startyear,endyear);
		        
		        
		        FusionCharts cb=new FusionCharts("科技成果体现形式分布统计");
	    		
	    		cb.setXAxisName("年份");
	    		cb.setYAxisName("成果数量");
	    		cb.setChartAttribute("LABELDISPLAY", "Rotate");
	    		cb.setChartAttribute("SLANTLABELS", "1");
	    		
	    		//各种分类的数量
	    		Map countMap = new HashMap();
	    		
	    		Map tmap = new HashMap();
	    		double sum = 0;
	    		for(int i=0;i<recordSet.size();i++){
	    			Record record = recordSet.get(i);
	    			cb.addDataByNoLink(record.getString("KJCG_YEAR",""),record.getString("XXMC",""),new Integer(record.getString("TOTAL","0")).intValue());
	    			
	    			sum += new Double(record.getString("TOTAL","0")).doubleValue();
	    			
	    			tmap.put(record.getString("KJCG_YEAR","")+record.getString("XXMC",""), record.getString("TOTAL","0"));
	    			
	    			if(countMap.get(record.getString("XXMC",""))==null){
	    				countMap.put(record.getString("XXMC",""), new Integer(record.getString("TOTAL","0")));
	    			}else{
	    				countMap.put(record.getString("XXMC",""),((Integer)countMap.get(record.getString("XXMC",""))).intValue() + new Integer(record.getString("TOTAL","0")).intValue());
	    			}
	    		}
	    		
	    		UserNeedsHandler uhandler = new UserNeedsHandler();
	    		RecordSet ktdmSet =  uhandler.getZdxx("ITEM_123");
	    		
	    		//不存在的分类填充0
	    		for(int i=new Integer(startyear).intValue();i<=new Integer(endyear).intValue();i++){
	    			for(int j=0;j<ktdmSet.size();j++){
	    				if(tmap.get(new Integer(i).toString()+ktdmSet.get(j).getString("XXMC", ""))==null){
	    					cb.addDataByNoLink(new Integer(i).toString(),ktdmSet.get(j).getString("XXMC", ""),0);
	    				}
	    			}
	    		}
	    		
	    		//记录各分类数量
	    		for(int i=0;i<ktdmSet.size();i++){
	    			String total = "";
	    			if(countMap.get(ktdmSet.get(i).getString("XXMC",""))!=null){
	    				total = ((Integer)(countMap.get(ktdmSet.get(i).getString("XXMC","")))).toString();
	    				double total_d = new Double(total).doubleValue(); 
		    			double per_d = total_d/sum*100;
		    		    (ktdmSet.get(i)).addData("TOTAL", total);
		    			 DecimalFormat df = new DecimalFormat("##.##");  
		    			 (ktdmSet.get(i)).addData("PER", df.format(per_d));
	    			}else{
	    				(ktdmSet.get(i)).addData("TOTAL", "0");
		    			(ktdmSet.get(i)).addData("PER", "0.0");
	    			}
	    		}
	    		
	    		
	    		
	    		
	    		
	    		
	    		
	    		FusionCharts cb2=new FusionCharts("科技成果体现形式分布统计");
	    		
	    		for(int i=0;i<ktdmSet.size();i++){
	    			Record record = ktdmSet.get(i);
	    			cb2.addDataByNoLink(record.getString("XXMC",""),new Double(record.getString("TOTAL")).doubleValue());
	    		}
	    		
		        
	    		String filepath = "/stat/xml/"+UUIDGenerator.getUUID()+".xml";
	    		String realpath = request.getRealPath(filepath);
	    		String url1 = filepath;
	    		File xmlFile = new File(realpath);
	    		cb.saveDataAsXml("MSColumn3D", xmlFile);
	    		
	    		filepath = "/stat/xml/"+UUIDGenerator.getUUID()+".xml";
	    		realpath = request.getRealPath(filepath);
	    		String url2 = filepath;
	    		xmlFile = new File(realpath);
	    		cb2.saveDataAsXml("Pie3D", xmlFile);
	    		
	    		request.setAttribute("sum", sum);
	    		request.setAttribute("recordSet", recordSet);
		        request.setAttribute("searchRcd", searchRcd);
		        request.setAttribute("ktdmSet", ktdmSet);
		        request.setAttribute("url1", url1);
		        request.setAttribute("url2", url2);
		        request.setAttribute("countMap", countMap);
		        
		       // request.setAttribute("url2", url2);
				
				forward("/stat/TiXianXingshiShi.jsp");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} catch (ServletException e) {
			e.printStackTrace();
		} 
    }
    
    
    
    
    
    
    /**
     * 按行业分类
     * 
     * @param request
     * @param response
     */
    public void hangYe(HttpServletRequest request,HttpServletResponse response)
    {
    	try { 
			try {
				
				RequestKit requestKit = (RequestKit) request.getAttribute("RequestKit");
		        
				Record searchRcd = requestKit.getRecordWithPrefix("sea_");
				
				String startyear = requestKit.getParameter("sea_startyear", "");
	            String endyear = requestKit.getParameter("sea_endyear", "");
	            
	            if(startyear.equals("")&&endyear.equals("")){
	            	endyear = DateUtility.getCurrentDate().substring(0,4);
	            	startyear = new Integer(new Integer(endyear).intValue()-6).toString();
	            	searchRcd.addData("STARTYEAR", startyear);
	            	searchRcd.addData("ENDYEAR", endyear);
	            }
		        
		        
		        StatHandler infoRecom = new StatHandler();
		        RecordSet recordSet = infoRecom.hangYe(startyear,endyear);
		        
		        
		        FusionCharts cb=new FusionCharts("科技成果分类统计");
	    		
	    		cb.setXAxisName("年份");
	    		cb.setYAxisName("成果数量");
	    		cb.setChartAttribute("LABELDISPLAY", "Rotate");
	    		cb.setChartAttribute("SLANTLABELS", "1");
	    		
	    		//各种分类的数量
	    		Map countMap = new HashMap();
	    		
	    		Map tmap = new HashMap();
	    		double sum = 0;
	    		for(int i=0;i<recordSet.size();i++){
	    			Record record = recordSet.get(i);
	    			cb.addDataByNoLink(record.getString("KJCG_YEAR",""),record.getString("XXMC",""),new Integer(record.getString("TOTAL","0")).intValue());
	    			
	    			sum += new Double(record.getString("TOTAL","0")).doubleValue();
	    			
	    			tmap.put(record.getString("KJCG_YEAR","")+record.getString("XXMC",""), record.getString("TOTAL","0"));
	    			
	    			if(countMap.get(record.getString("XXMC",""))==null){
	    				countMap.put(record.getString("XXMC",""), new Integer(record.getString("TOTAL","0")));
	    			}else{
	    				countMap.put(record.getString("XXMC",""),((Integer)countMap.get(record.getString("XXMC",""))).intValue() + new Integer(record.getString("TOTAL","0")).intValue());
	    			}
	    		}
	    		
	    		//得到行业分类
	    		RecordSet ktdmSet =  infoRecom.getHyTypes();
	    		
	    		//不存在的分类填充0 
	    		for(int i=new Integer(startyear).intValue();i<=new Integer(endyear).intValue();i++){
	    			for(int j=0;j<ktdmSet.size();j++){
	    				if(tmap.get(new Integer(i).toString()+ktdmSet.get(j).getString("XXMC", ""))==null){
	    					cb.addDataByNoLink(new Integer(i).toString(),ktdmSet.get(j).getString("XXMC", ""),0);
	    				}
	    			}
	    		}
	    		
	    		//记录各分类数量
	    		for(int i=0;i<ktdmSet.size();i++){
	    			String total = "";
	    			if(countMap.get(ktdmSet.get(i).getString("XXMC",""))!=null){
	    				total = ((Integer)(countMap.get(ktdmSet.get(i).getString("XXMC","")))).toString();
	    				double total_d = new Double(total).doubleValue(); 
		    			double per_d = total_d/sum*100;
		    		    (ktdmSet.get(i)).addData("TOTAL", total);
		    			 DecimalFormat df = new DecimalFormat("##.##");  
		    			 (ktdmSet.get(i)).addData("PER", df.format(per_d));
	    			}else{
	    				(ktdmSet.get(i)).addData("TOTAL", "0");
		    			(ktdmSet.get(i)).addData("PER", "0.0");
	    			}
	    		}
	    		
	    		
	    		
	    		
	    		
	    		
	    		
	    		FusionCharts cb2=new FusionCharts("科技成果分类统计");
	    		
	    		for(int i=0;i<ktdmSet.size();i++){
	    			Record record = ktdmSet.get(i);
	    			cb2.addDataByNoLink(record.getString("XXMC",""),new Double(record.getString("TOTAL")).doubleValue());
	    		}
	    		
		        
	    		String filepath = "/stat/xml/"+UUIDGenerator.getUUID()+".xml";
	    		String realpath = request.getRealPath(filepath);
	    		String url1 = filepath;
	    		File xmlFile = new File(realpath);
	    		cb.saveDataAsXml("MSColumn3D", xmlFile);
	    		
	    		filepath = "/stat/xml/"+UUIDGenerator.getUUID()+".xml";
	    		realpath = request.getRealPath(filepath);
	    		String url2 = filepath;
	    		xmlFile = new File(realpath);
	    		cb2.saveDataAsXml("Pie3D", xmlFile);
	    		
	    		
	    		
	    		request.setAttribute("sum", sum);
	    		request.setAttribute("recordSet", recordSet);
		        request.setAttribute("searchRcd", searchRcd);
		        request.setAttribute("ktdmSet", ktdmSet);
		        request.setAttribute("url1", url1);
		        request.setAttribute("url2", url2);
		        request.setAttribute("countMap", countMap);
		        
		       // request.setAttribute("url2", url2);
				
				forward("/stat/HangYe.jsp");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} catch (ServletException e) {
			e.printStackTrace();
		} 
    }
    
    
    
    
    
    
    
    
    /**
     * 单位成果数量统计TOP10
     * 
     * @param request
     * @param response
     */
    public void unitAchieveTop10(HttpServletRequest request,HttpServletResponse response)
    {
    	try { 
			try {
				
				RequestKit requestKit = (RequestKit) request.getAttribute("RequestKit");
		         
		 		Record searchRcd = requestKit.getRecordWithPrefix("sea_");
				
				String startyear = requestKit.getParameter("sea_startyear", "");
	            String endyear = requestKit.getParameter("sea_endyear", "");
	            String newenergyclass1 = requestKit.getParameter("sea_NewEnergyClass1", "");
	            
	            /*if(startyear.equals("")&&endyear.equals("")){
	            	endyear = DateUtility.getCurrentDate().substring(0,4);
	            	startyear = new Integer(new Integer(endyear).intValue()-6).toString();
	            	searchRcd.addData("STARTYEAR", startyear);
	            	searchRcd.addData("ENDYEAR", endyear);
	            }*/
		        
		        
		        StatHandler infoRecom = new StatHandler();
		        RecordSet recordSet = infoRecom.unitAchieveTop10(startyear,endyear,newenergyclass1);
		        
		        
		        FusionCharts cb=new FusionCharts("单位成果数量TOP"+searchRcd.getString("TOPNUM","10"));
	    		
	    		cb.setXAxisName("单位");
	    		cb.setYAxisName("成果数量");
	    		cb.setChartAttribute("LABELDISPLAY", "Rotate");
	    		cb.setChartAttribute("SLANTLABELS", "1");
	    		
	    		
	    		int sum = 0;
	    		for(int i=0;i<recordSet.size()&&i<new Integer(searchRcd.getString("TOPNUM","10")).intValue();i++){
	    			Record record = recordSet.get(i);
	    			cb.addDataByNoLink(record.getString("KJCG_YEAR",""),record.getString("XXMC","").trim(),new Integer(record.getString("TOTAL","0")).intValue());
	    			
	    			sum += new Integer(record.getString("TOTAL","0")).intValue();
	    			
	    		}
	    		
	    		
	    		
	    		FusionCharts cb2=new FusionCharts("单位成果数量TOP"+searchRcd.getString("TOPNUM","10"));
	    		
	    		for(int i=0;i<recordSet.size()&&i<new Integer(searchRcd.getString("TOPNUM","10")).intValue();i++){
	    			Record record = recordSet.get(i);
	    			cb2.addDataByNoLink(record.getString("XXMC","").trim(),new Double(record.getString("TOTAL")).doubleValue());
	    		}
	    		
		        
	    		String filepath = "/stat/xml/"+UUIDGenerator.getUUID()+".xml";
	    		String realpath = request.getRealPath(filepath);
	    		String url1 = filepath;
	    		File xmlFile = new File(realpath);
	    		cb.saveDataAsXml("MSColumn3D", xmlFile);
	    		
	    		filepath = "/stat/xml/"+UUIDGenerator.getUUID()+".xml";
	    		realpath = request.getRealPath(filepath);
	    		String url2 = filepath;
	    		xmlFile = new File(realpath);
	    		cb2.saveDataAsXml("Pie3D", xmlFile);
	    		
	    		
	    		
	    		
	    		AchieveHandler ahandler = new AchieveHandler();
	    		RecordSet hyRset = new RecordSet();
	    		hyRset.add(ahandler.getNewEnergyClassList());
	    		
	    		
	    		
	    		request.setAttribute("recordSet", recordSet);
		        request.setAttribute("searchRcd", searchRcd);
		        request.setAttribute("hyRset", hyRset);
		        request.setAttribute("sum", sum);
		        request.setAttribute("url1", url1);
		        request.setAttribute("url2", url2);
				forward("/stat/UnitAchieveTop10.jsp");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} catch (ServletException e) {
			e.printStackTrace();
		} 
    }
    
    
    
    
    
    
}
